package com.example.sunmiv1.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.sunmiv1.R;
import com.example.sunmiv1.entity.VipRechargeListBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class VipRechargeAdapter extends BaseAdapter {

    private Context context;
    private List<VipRechargeListBean.RechargeActivityBean.VipRechargeActivityBean> list;
    private int index = 9999;
    private ViewHolder viewHolder;

    public void isSelect(int index) {
        this.index = index;
        notifyDataSetChanged();
    }

    public VipRechargeAdapter(Context context, List<VipRechargeListBean.RechargeActivityBean.VipRechargeActivityBean> list) {
        this.context = context;
        this.list = list;
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        VipRechargeListBean.RechargeActivityBean.VipRechargeActivityBean bean = list.get(position);
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.vip_recharge_adapter, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if (index == position) {
            viewHolder.vipRechargeLin.setBackgroundResource(R.drawable.member_login_sure_red);
            viewHolder.vipRechargeRecharge.setTextColor(context.getResources().getColor(R.color.white));
            viewHolder.vipRechargeDefault.setTextColor(context.getResources().getColor(R.color.white));
            viewHolder.vipRechargeGive.setTextColor(context.getResources().getColor(R.color.white));
            viewHolder.memberCouponStage.setTextColor(context.getResources().getColor(R.color.white));
        } else {
            viewHolder.vipRechargeLin.setBackgroundResource(R.drawable.vip_details_edit_bg);
            viewHolder.vipRechargeRecharge.setTextColor(context.getResources().getColor(R.color.text_333));
            viewHolder.vipRechargeDefault.setTextColor(context.getResources().getColor(R.color.text_333));
            viewHolder.vipRechargeGive.setTextColor(context.getResources().getColor(R.color.login_textColor1));
            viewHolder.memberCouponStage.setTextColor(context.getResources().getColor(R.color.login_textColor1));
        }
        if ("0".equals(list.get(position).getId())) {
            viewHolder.vipRechargeDefault.setVisibility(View.VISIBLE);
            viewHolder.vipRechargeRecharge.setVisibility(View.GONE);
            viewHolder.vipRechargeGive.setVisibility(View.GONE);
        } else {
            viewHolder.vipRechargeDefault.setVisibility(View.GONE);
            viewHolder.vipRechargeRecharge.setVisibility(View.VISIBLE);
            viewHolder.vipRechargeGive.setVisibility(View.VISIBLE);
            viewHolder.vipRechargeRecharge.setText(context.getString(R.string.vipRechargeAdapter1) + list.get(position).getRecharge_money());
            viewHolder.vipRechargeGive.setText(context.getString(R.string.vipRechargeAdapter2) + list.get(position).getGive_money());
            if ("1".equals(bean.getAging_repay())) {//分期到賬
                viewHolder.memberCouponStage.setVisibility(View.VISIBLE);
                viewHolder.memberCouponStage.setText(context.getString(R.string.vipRechargeAdapter3) + bean.getActive_aging_time() + context.getString(R.string.vipRechargeAdapter4));
            } else {//直接到賬
                viewHolder.memberCouponStage.setVisibility(View.INVISIBLE);
            }
        }
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.vipRecharge_default)
        TextView vipRechargeDefault;
        @BindView(R.id.vipRecharge_recharge)
        TextView vipRechargeRecharge;
        @BindView(R.id.vipRecharge_give)
        TextView vipRechargeGive;
        @BindView(R.id.memberCoupon_stage)
        TextView memberCouponStage;
        @BindView(R.id.vipRecharge_lin)
        LinearLayout vipRechargeLin;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
